//
//  UIButton+Pyw.m
//  pyw_Demo
//
//  Created by smallwave on 16/4/5.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "UIButton+Pyw.h"
#import "PywCommonManager.h"

@implementation UIButton (Pyw)

+ (instancetype)buttonWithBackgroundColor:(UIColor *)backgroundColor
                               titleColor:(UIColor *)titlieColor
                       titleLabelFontSize:(CGFloat)titleLabelFontSize
                                    title:(NSString *)title{
    
    return [self buttonWithBackgroundColor:backgroundColor
                              cornerRadius:5.0
                                titleColor:titlieColor
                        titleLabelFontSize:titleLabelFontSize
                                     title:title];
}

+ (instancetype)buttonWithBackgroundColor:(UIColor *)backgroundColor
                             cornerRadius:(CGFloat)cornerRadius
                               titleColor:(UIColor *)titlieColor
                       titleLabelFontSize:(CGFloat)titleLabelFontSize
                                    title:(NSString *)title{
    CGFloat fontSize = [[PywCommonManager manager] changeDeviceTextFontSize:titleLabelFontSize];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.layer.cornerRadius = cornerRadius;
    button.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    button.backgroundColor = backgroundColor;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titlieColor forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    
    if ([self isTheSameColor2:[UIColor whiteColor] anotherColor:titlieColor]) {
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    } else if ([self isTheSameColor2:[UIColor blackColor] anotherColor:titlieColor]){
        [button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
    }
    return button;
}
+ (BOOL) isTheSameColor2:(UIColor*)color1 anotherColor:(UIColor*)color2
{
    if (CGColorEqualToColor(color1.CGColor, color2.CGColor)) {
        return YES;
    }
    else {
        return NO;
    }
}

@end
